Option Strict On
Option Explicit On

Imports System

Imports KadGen.FriendlySchemaWrapper

Partial Public Class XmlAdapter

   Private Shared Function GetDataStructure(ByVal dataStructureNode As Xml.XmlNode) As DataStructure

      Dim name As String = Utility.XmlHelpers.GetAttributeOrEmptyString(dataStructureNode, "Name")

      Return New DataStructure(name)

   End Function

   Private Shared Function GetObjectDef(ByVal objectDefNode As Xml.XmlNode) As ObjectDef
      Dim name As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "Name")
      Dim prefix As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "Prefix")
      Dim group As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "Group")
      Dim originalName As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "OriginalName")
      Dim singularName As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "SingularName")
      Dim pluralName As String = Utility.XmlHelpers.GetAttributeOrEmptyString(objectDefNode, "PluralName")
      Dim isCollection As Boolean = Utility.XmlHelpers.GetAttributeBooleanOrFalse(objectDefNode, "IsCollection")

      Return New ObjectDef(name, prefix, group, originalName, singularName, pluralName, isCollection)

   End Function

   Private Shared Function GetPropertyDef(ByVal propertyDefNode As Xml.XmlNode) As PropertyDef

      Dim name As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "Name")
      Dim originalName As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "OriginalName")
      Dim ordinal As Int32 = Utility.XmlHelpers.GetAttributeIntegerOrZero(propertyDefNode, "Ordinal")
      Dim defaultValue As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "DefaultValue")
      Dim allowNulls As Boolean = Utility.XmlHelpers.GetAttributeBooleanOrFalse(propertyDefNode, "AllowNulls")
      Dim originalType As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "OriginalType")
      Dim sqlType As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "SQLType")
      Dim netType As String = Utility.XmlHelpers.GetAttributeOrEmptyString(PropertyDefNode, "NETType")

      Return New PropertyDef(name, originalName, ordinal, defaultValue, allowNulls, originalType, sqlType, netType)

   End Function

   Private Shared Function GetConstraint(ByVal constraintNode As Xml.XmlNode) As Constraint

      Dim relations As String = Utility.XmlHelpers.GetAttributeOrEmptyString(constraintNode, "Relations")

      Return New Constraint(relations)

   End Function


End Class
